home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c
- Subject: Re: Fixing stack overflow??
- Date: 23 Mar 1996 17:14:20 GMT
- Organization: Borland International
- Distribution: world
- Message-ID: <4j1bhc$dpc@druid.borland.com>
- References: <4is899$cg7$1@mhafc.production.compuserve.com> <Pine.A32.3.91.960322143127.23347J-100000@red.weeg.uiowa.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <Pine.A32.3.91.960322143127.23347J-100000@red.weeg.uiowa.edu>,
- robinson@blue.weeg.uiowa.edu says...
- >
- >On 21 Mar 1996, Tom wrote:
- >
- >> I'm using Borland's C compiler and I am getting a stack
- >> overflow. How can I fix this?
- >
- >1. Ask for a bigger stack (your compiler docs should have some ideas about
- >how to do that).
- >2. Don't declare enormous arrays as local variables.
- >3. Don't rely on really deep recursion, especially if each invocation of
- >the recursive function declares an enormous array. :-)
-
- Let me add that number 1 is rarely the best answer. The key, as ever, is to
- understand why the problem is occurring and then to fix it. I once had to
- overhaul some code that someone else had written. They insisted that they
- needed a 32k stack. The culprit was a really bad implementation of a string
- class they had written that contained a 256 byte char array, combined with
- string operations that created lots of temporary strings along the way. (Yes,
- this was C++ code, but the point is still valid for C) Getting rid of this
- beast and changing to C-style char arrays reduced the stack requirements to 8k.
- -- Pete
-
-